<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加代理商</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
    <style>
        .layui-form{
            margin: 10px;
        }
    </style>
</head>
<body class="childrenBody">
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">代理商名称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" lay-verify="required" name="name" placeholder="请输入代理商名称">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">联系人</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="linkman" lay-verify="required" placeholder="请输入联系人">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号码</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="phone" lay-verify="required||phone" placeholder="请输入手机号码">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">固定电话</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="landline" lay-verify="required" placeholder="请输入固定电话">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="username" lay-verify="required" placeholder="请输入登录账号" autocomplete="off">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="password" class="layui-input" name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="addAgents">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<script type="text/javascript">
    layui.config({
        base: "js/"
    }).use(['form', 'layer', 'jquery'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : parent.layer,
            $ = layui.jquery;
        form.on("submit(addAgents)", function (data) {
            var datas = data.field;
            var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
            $.ajax({
                type: "POST",
                url: "/agents",
                data: JSON.stringify(datas),
                contentType: "application/json",
                success: function (res) {
                    top.layer.close(index);
                    top.layer.msg(res.msg);
                    if (res.code == 2000) {
                        layer.closeAll("iframe");
                        parent.location.reload();
                    }
                },
                error: function (res) {
                    layer.msg("请求错误")
                }
            });
            return false;
        })
    })
</script>
</body>
</html>

